﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Torch_Services
{
    public class CopyrightBll : ICopyrightBll
    {
        private ICopyrightDal _copy;
        private IMapper _mapper;
        public CopyrightBll(ICopyrightDal copy, IMapper mapper)
        {
            _copy = copy;
            _mapper = mapper;
        }

        public async Task<int> AddCopyrightAsync(string title, string content, string logo, string image, string photo, string telephone, string fax, string qq, string weChat, string email, string address)
        {
            return await _copy.AddAsync(new Copyright 
            {
                Title = title,
                Content = content,
                Logo = logo,
                Images = image,
                Phone = photo,
                Telephone = telephone,
                Fax = fax,
                Qq = qq,
                WeChat = weChat,
                Email = email,
                Address = address
            });
        }

        public async Task<int> DeleteCopyrightAsync(int id)
        {
            var data = await _copy.QueryAsync(id);
            return data == null ? -1 : await _copy.DeleteAsync(data);
        }

        public async Task<int> EditCopyrightAsync(int id, string title, string content, string logo, string image, string photo, string telephone, string fax, string qq, string weChat, string email, string address)
        {
            var data = await _copy.QueryAsync(id);
            if (data == null)
                return -1;
            data.Title = title;
            data.Content = content;
            data.Logo = logo;
            data.Images = image;
            data.Phone = photo;
            data.Telephone = telephone;
            data.Fax = fax;
            data.Qq = qq;
            data.WeChat = weChat;
            data.Email = email;
            data.Address = address;
            return await _copy.EditAsync(data);
        }

        public async Task<List<CopyrightDto>> GetCopyrightAllAsync()
        {
            var data = await _copy.QueryAsync();
            return _mapper.Map<List<Copyright>,List<CopyrightDto>>(data);
        }

        public async Task<CopyrightDto> QueryCopyrightByIdAsync(int id)
        {
            var data = await _copy.QueryAsync(id);
            return _mapper.Map<Copyright,CopyrightDto>(data);
        }
    }
}
